cms_player.yun=false;

var s = '<video class="embed-responsive-item  video-js  vjs-tech vjs-default-skin vjs-big-play-centered vjs-16-9"   ' +
    ' controls preload="auto" playsinline  id="video"  data-setup="{}" style="background:#000;" >' +
    '<source src="'+cms_player.url+'"';
    // if(cms_player.videoType){
    //     s += ' type="'+cms_player.videoType+'"';
    // }
    s += '">您的浏览器不支持 HTML5 video 标签。</video>'
console.info(s);
document.write(s);

try{

//document.getElementById("video").onended=function(){if(cms_player.next_path){location.href=cms_player.next_path;}};

    //设置中文
    videojs.addLanguage('zh-CN', {
        "Play": "播放",
        "Pause": "暂停",
        "Current Time": "当前时间",
        "Duration": "时长",
        "Remaining Time": "剩余时间",
        "Stream Type": "媒体流类型",
        "LIVE": "直播",
        "Loaded": "加载完毕",
        "Progress": "进度",
        "Fullscreen": "全屏",
        "Non-Fullscreen": "退出全屏",
        "Mute": "静音",
        "Unmute": "取消静音",
        "Playback Rate": "播放速度",
        "Subtitles": "字幕",
        "subtitles off": "关闭字幕",
        "Captions": "内嵌字幕",
        "captions off": "关闭内嵌字幕",
        "Chapters": "节目段落",
        "Close Modal Dialog": "关闭弹窗",
        "Descriptions": "描述",
        "descriptions off": "关闭描述",
        "Audio Track": "音轨",
        "You aborted the media playback": "视频播放被终止",
        "A network error caused the media download to fail part-way.": "网络错误导致视频下载中途失败。",
        "The media could not be loaded, either because the server or network failed or because the format is not supported.": "视频因格式不支持或者服务器或网络的问题无法加载。",
        "The media playback was aborted due to a corruption problem or because the media used features your browser did not support.": "由于视频文件损坏或是该视频使用了你的浏览器不支持的功能，播放终止。",
        "No compatible source was found for this media.": "无法找到此视频兼容的源。",
        "The media is encrypted and we do not have the keys to decrypt it.": "视频已加密，无法解密。",
        "Play Video": "播放视频",
        "Close": "关闭",
        "Modal Window": "弹窗",
        "This is a modal window": "这是一个弹窗",
        "This modal can be closed by pressing the Escape key or activating the close button.": "可以按ESC按键或启用关闭按钮来关闭此弹窗。",
        ", opens captions settings dialog": ", 开启标题设置弹窗",
        ", opens subtitles settings dialog": ", 开启字幕设置弹窗",
        ", opens descriptions settings dialog": ", 开启描述设置弹窗",
        ", selected": ", 选择",
        "captions settings": "字幕设定",
        "Audio Player": "音频播放器",
        "Video Player": "视频播放器",
        "Replay": "重播",
        "Progress Bar": "进度小节",
        "Volume Level": "音量",
        "subtitles settings": "字幕设定",
        "descriptions settings": "描述设定",
        "Text": "文字",
        "White": "白",
        "Black": "黑",
        "Red": "红",
        "Green": "绿",
        "Blue": "蓝",
        "Yellow": "黄",
        "Magenta": "紫红",
        "Cyan": "青",
        "Background": "背景",
        "Window": "视窗",
        "Transparent": "透明",
        "Semi-Transparent": "半透明",
        "Opaque": "不透明",
        "Font Size": "字体尺寸",
        "Text Edge Style": "字体边缘样式",
        "None": "无",
        "Raised": "浮雕",
        "Depressed": "压低",
        "Uniform": "均匀",
        "Dropshadow": "下阴影",
        "Font Family": "字体库",
        "Proportional Sans-Serif": "比例无细体",
        "Monospace Sans-Serif": "单间隔无细体",
        "Proportional Serif": "比例细体",
        "Monospace Serif": "单间隔细体",
        "Casual": "舒适",
        "Script": "手写体",
        "Small Caps": "小型大写字体",
        "Reset": "重启",
        "restore all settings to the default values": "恢复全部设定至预设值",
        "Done": "完成",
        "Caption Settings Dialog": "字幕设定视窗",
        "Beginning of dialog window. Escape will cancel and close the window.": "开始对话视窗。离开会取消及关闭视窗",
        "End of dialog window.": "结束对话视窗"
    });
    var videoObj = videojs('video');
    var option={};
    // var myPlayer = videojs('video',option,function onPlayerReady(){
    //     var myPlayer = this;
    //     myPlayer.src({src: cms_player.url, type: "application/x-mpegURL"});
    //     videojs.log("播放器已经准备好了!");
    //     this.play();
    // });
    var myPlayer = videojs('video');
    videojs("video").ready(function(){
        var myPlayer = this;
        //myPlayer.play();
        //------events    绑定事件用on    移除事件用off
        this.on('loadstart',function () {
            console.log('loadstart------------')
        });
        this.on('loadedmetadata',function () {
            console.log('loadedmetadata---视频源数据加载完成----')
        });
        this.on('loadeddata',function () {
            console.log('loadeddata---渲染播放画面----');//autoPlay必须为false
        });
        this.on('progress',function () {
            console.log('progress-------加载过程----')
            try{
                $('#video').before('<iframe id="cms_player_buffer" class="embed-responsive-item" src="'+cms_player.buffer+'" frameborder="0" scrolling="no" allowtransparency="true"></iframe>');

            }catch (e) {
            console.error('progress------error',e);
        }

        });

        this.on('stalled',function () {

            console.log('stalled-------------');
        })
        this.on('waiting',function () {

            console.log('waiting-------------');
        })
        this.on('seeking',function () {

            console.log('seeking-------------');
        })
        this.on('seeked',function () {

            console.log('seeked-------------');
        })
        this.on('timeupdate',function () {
            var curTime = this.currentTime();
             console.log('timeupdate-------------',curTime);
        })
        this.on('canplay',function () {
            console.log('canplay----------')
            option.canplay = true;

        })
        this.on('pause',function () {
            try{
                    console.log('pause-------------');

                    if(option.canplay || typeof option.canplay =='undefined' ){
                        $width = $('#video').width()/2;
                        $height = $('#video').height()/2;
                        $top = $('#video').height()/4;
                        $left = $('#video').width()/4;
                        $('#video').before('<iframe id="cms_player_pause" class="embed-responsive-item" src="'+cms_player.pause+'" frameborder="0" scrolling="no" allowtransparency="true" style="position:absolute;z-index:2;top:'+$top+'px;left:'+$left+'px;width:'+$width+'px;height:'+$height+'px"></iframe>');

                    }
            }catch (e) {
                    console.error('play------error',e);
                }

        })
        this.on('play',function () {
                try{
                    console.log('play-------------');
                    $('#cms_player_buffer').remove();
                    $('#cms_player_pause').remove();
                }catch (e) {
                    console.error('play------error',e);
                }

        })
        this.on('suspend',function () {

            console.log('suspend-------------');
        })
        this.on('emptied',function () {

            console.log('emptied-------------');
        })
    });
    /*让视频跳转到一个进度,单位是秒*/
    function tiaozhuan1(){
        videoObj.currentTime(120);
    }
    /*currentTime是获取当前视频的播放时间,我这里让它转成了xx:xx:xx的格式*/
    function huoqu1(){
        var videoTime = videoObj.currentTime();
        //获取视频有几个小时
        var h = Math.floor(videoTime / 3600);
        //获取视频有多少分钟
        var m = Math.floor(videoTime % 3600 / 60);
        //获取视频有多少秒
        var s = Math.floor(videoTime % 60);
        //将视频格式化为xx:xx:xx,比如1个小时12分钟11秒的视频就是01:12:11
        console.log((h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s));
        console.log(videoTime);
    }
    /*这里我切换了一个新的视频源*/
    function qiehuan1(){
       // videoObj.src({src: "index.m3u8", type: "application/x-mpegURL"});
    }
    /*这样可以获取视频的总长度,单位是秒*/
    function huoqushijian1(){
        var howLongIsThis = videoObj.duration();
        console.log(howLongIsThis);

    }
    /*这样是再加载视频时会执行的函数,每次切换视频源都会调用此函数*/
    videoObj.on("loadedmetadata",function(){
        console.log("正在读取配置信息")
    });
    videoObj.on("ended", function() {
        if(cms_player.next_path){
            top.location.href = cms_player.next_path;
        }
    });
}catch (e) {
    console.error("加载视频异常,url ="+cms_player.url,e);
    //alert("加载视频异常");
}